package com.jiulan.hearthearing.ui.my.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.jiulan.hearthearing.R;
import com.jiulan.hearthearing.base.BaseActivity;
import com.jiulan.hearthearing.ui.my.fragment.CoursesPurchasedFragment;

/**
 * 已购课程
 */
public class CoursesPurchasedActivity extends BaseActivity {
    private CoursePagerAdapter mAdapter;
    private String[] mTitle = {"全部", "课程", "个案", "解析"};

    private TabLayout mTabLayout;
    private ViewPager mViewPager;

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, CoursesPurchasedActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_courses_purchased;
    }

    @Override
    protected void initView() {
        setTitleText("已购课程");
        mTabLayout = findViewById(R.id.tabs);
        mViewPager = findViewById(R.id.viewpager);
        mViewPager.setOffscreenPageLimit(mTitle.length);
        mAdapter = new CoursePagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    class CoursePagerAdapter extends FragmentPagerAdapter {

        public CoursePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return CoursesPurchasedFragment.newInstance(i);
        }

        @Override
        public int getCount() {
            return mTitle.length;
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return mTitle[position];
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getTitleBarType() {
        return TITLEBAR_DEFAULT;
    }
}
